// JavaScript Document

var scrollTime; // 全局变量timeout

$(document).ready(function(){
    var $bannerlongUl = $(".bannerlong ul");
    var $bannerlongUlLi = $(".bannerlong ul li");
    var $bodyWidth = 640;
    var $bannerLength = $bannerlongUlLi.length;
    $bannerlongUl.css({"width":$bodyWidth * $bannerLength}); //页面加载完成后赋值给banner容器
    $bannerlongUlLi.css({"width":$bodyWidth});
    $(".dot ul").css({"width":25*$bannerLength});
    $(".dot ul li").eq(0).addClass("active");
    scrollBanner($bodyWidth,1);


    $(".dot ul li").off().on('click',function(){ // dot点击操作，清除计时器，直接操作容器left值
        clearTimeout(scrollTime);
        var num = $(this).index();
        $bannerlongUl.animate({"left":-$bodyWidth * num},"slow");
        $(".dot ul li.active").removeClass("active");
        $(".dot ul li").eq(num).addClass("active");
        scrollBanner($bodyWidth,num+1); //操作完成后重设计时器
    });

    $(".clearInputText").off().on('click',function(){
        $('#detail_form')[0].reset();
    });

});

function scrollBanner(width,i){
    var $bannerlongUl = $(".bannerlong ul");
    var $bannerlongUlLi = $(".bannerlong ul li");
    var $bannerLength = $bannerlongUlLi.length;
    if( i < $bannerLength ){
        scrollTime = setTimeout(function(){
            $bannerlongUl.animate({"left":-width * i},"slow");
            $(".dot ul li.active").removeClass("active");
            $(".dot ul li").eq(i).addClass("active");
            clearTimeout(scrollTime);
            i++;
            scrollBanner(width,i);
        },3000);
    }else{
        scrollBanner(width,0);
    }
}